<?php
$connection = Yii::app()->db;
Yii::import('ext.chosen.Chosen');

#Get Sponsor List   
$sql = "SELECT member_id, first_name, last_name FROM gn_members";
$command = $connection->createCommand($sql);
$dataReader = $command->query();
$members = array();
$members[0] = "0 Business Center";
foreach( $dataReader as $row ) { 
  $members[$row['member_id']] = $row['member_id'].' '.$row['last_name']. ', ' . $row['first_name']; 
}


$sql = "SELECT * FROM gn_provinces";
$command = $connection->createCommand($sql);
$dataReader = $command->query();
$provinces = array();
foreach( $dataReader as $row ) { 
  $provinces[$row['province_id']] = $row['province'];
}

$sql = "SELECT * FROM gn_member_status";
$command = $connection->createCommand($sql);
$dataReader = $command->query();
$status = array();
foreach( $dataReader as $row ) { 
  $status[$row['status_id']] = $row['status'];
}

?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'members-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

    <fieldset>
    <table border="0">
    <tr>
      <td>
        <div class="row" align="right">
            <?php echo $form->labelEx($model,'sponsor_id'); ?>
            <?php //Chosen::dropDownList('sponsor_id', array('name'=>'sponsor_id'), $members,  array('style' => 'width:360px')); ?>
            <?php $this->widget('ext.chosen.Chosen',array('name' => 'Members[sponsor_id]', 'value'=>$model->sponsor_id,  'id'=> 'Members_sponsor_id', 'data' => $members, 'htmlOptions' => array('style' => 'width:200px; alignment: left;') ));?>
            <?php //echo $form->dropDownList($model,'sponsor_id', $members ); ?>
            <?php echo $form->error($model,'sponsor_id'); ?>
        </div>
      </td>
      <td>            
        <div class="row" align="right">
            <?php echo $form->labelEx($model,'position'); ?>
            <?php echo $form->dropDownList($model,'position',array('left'=> 'Left','right'=>'Right')); ?>
            <?php echo $form->error($model,'position'); ?>
        </div>
      </td>
      <td>
         <div class="row" align="right">
            <!--
            <?php echo $form->labelEx($model,'date_joined'); ?>
            <?php if ( $model->isNewRecord ) { 
			      $date = date("Y-m-d"); 
				  ?>
              <?php echo $form->textField($model,'date_joined', array( 'value'=> $date ) ); ?>
            <?php } else { ?>
              <?php echo $form->textField($model,'date_joined'); ?>
            <?php } ?>
            <?php echo $form->error($model,'date_joined'); ?>
            -->
            <?php echo CHtml::activeLabelEx($model,'date_joined'); ?>
            <?php if ( $model->isNewRecord ) { 
			      $date = date("Y-m-d"); ?>
              <?php echo CHtml::activeTextField($model,'date_joined',array("id"=>"date_joined", 'value'=>$date)); ?>
            <?php } else { ?>
               <?php echo CHtml::activeTextField($model,'date_joined',array("id"=>"date_joined")); ?>
            <?php } ?>
            <!--&nbsp;(calendar appears when textbox is clicked)-->
            <?php $this->widget('application.extensions.calendar.SCalendar',
                array(
                'inputField'=>'date_joined',
                'ifFormat'=>'%Y-%m-%d',
            ));
            ?>
         </div>
      </td>
    </tr>
    </table>
    </fieldset>
    
    
    <fieldset>
    <table border="0">
    <tr>
       <td>
            <div class="row">
				<?php echo $form->labelEx($model,'salute'); ?>
                  <?php echo $form->dropDownList($model,'salute',array( 'MR'=>'MR', 'MS'=>'MS') ); ?>
                <?php echo $form->error($model,'salute'); ?>
            </div>
       </td>
       <td>
            <div class="row">
				<?php echo $form->labelEx($model,'first_name'); ?>
                <?php echo $form->textField($model,'first_name',array('size'=>25,'maxlength'=>32)); ?>
                <?php echo $form->error($model,'first_name'); ?>
            </div>
        </td>
        <td>
            <div class="row">
                <?php echo $form->labelEx($model,'last_name'); ?>
                <?php echo $form->textField($model,'last_name',array('size'=>25,'maxlength'=>32)); ?>
                <?php echo $form->error($model,'last_name'); ?>
            </div>
        </td>
        <td>
            <div class="row">
                <?php echo $form->labelEx($model,'middle_name'); ?>
                <?php echo $form->textField($model,'middle_name',array('size'=>25,'maxlength'=>32)); ?>
                <?php echo $form->error($model,'middle_name'); ?>
            </div>
       </td>
    </tr>
    </table>
    
    <table border="0">
    <tr>
      <td>
         <div class="row">
            <!--
            <?php echo $form->labelEx($model,'birthday'); ?>
            <?php echo $form->textField($model,'birthday'); ?>
            <?php echo $form->error($model,'birthday'); ?>
            -->
            <?php echo CHtml::activeLabelEx($model,'birthday'); ?>
            <?php echo CHtml::activeTextField($model,'birthday',array("id"=>"birthday")); ?>
           <!--  &nbsp;(calendar appears when textbox is clicked) -->
            <?php $this->widget('application.extensions.calendar.SCalendar',
                array(
                'inputField'=>'birthday',
                'ifFormat'=>'%Y-%m-%d',
            ));
            ?>
        </div>
      </td>
      <td valign="top">
        <div class="row">
            <?php echo $form->labelEx($model,'tin'); ?>
            <?php echo $form->textField($model,'tin',array('size'=>20,'maxlength'=>45)); ?>
            <?php echo $form->error($model,'tin'); ?>
        </div>
      </td>
      <td valign="top">
        <div class="row">
            <?php echo $form->labelEx($model,'nationality'); ?>
            <?php echo $form->textField($model,'nationality',array('size'=>20,'maxlength'=>45)); ?>
            <?php echo $form->error($model,'nationality'); ?>
        </div>
      </td>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'acr_no'); ?>
            <?php echo $form->textField($model,'acr_no',array('size'=>25,'maxlength'=>45)); ?>
            <?php echo $form->error($model,'acr_no'); ?>
        </div>
      </td>
    </tr>
    </table>
    
    </fieldset>
    
    <!--
	<div class="row">
		<?php echo $form->labelEx($model,'salute'); ?>
        <div class="compactRadioGroup">
		  <?php echo $form->radioButtonList($model,'salute',array( 'MR'=>'MR', 'MS'=>'MS'), array( 'separator' => " | ", 'checked'=> 'checked') ); ?>
		</div>
		<?php echo $form->error($model,'salute'); ?>
	</div>
    -->
    <fieldset>
    <table border="0">
    <tr>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'business_name'); ?>
            <?php echo $form->textField($model,'business_name',array('size'=>45,'maxlength'=>45)); ?>
            <?php echo $form->error($model,'business_name'); ?>
        </div>
      </td>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'business_type'); ?>
            <?php echo $form->textField($model,'business_type',array('size'=>20,'maxlength'=>45)); ?>
            <?php echo $form->error($model,'business_type'); ?>
        </div>
      </td>
      <td>  
        <div class="row">
            <?php echo $form->labelEx($model,'business_tin'); ?>
            <?php echo $form->textField($model,'business_tin',array('size'=>20,'maxlength'=>45)); ?>
            <?php echo $form->error($model,'business_tin'); ?>
        </div>
        <!--
        <div class="row">
            <?php echo $form->labelEx($model,'business_address'); ?>
            <?php echo $form->textField($model,'business_address',array('size'=>60,'maxlength'=>90)); ?>
            <?php echo $form->error($model,'business_address'); ?>
        </div>
        -->
      </td>
    </tr>
    </table>
     
    </fieldset>
    
    <fieldset>
    <table border="0">
    <tr>
      <td> 
        <div class="row">
            <?php echo $form->labelEx($model,'main_address'); ?>
            <?php echo $form->textField($model,'main_address',array('size'=>50,'maxlength'=>90)); ?>
            <?php echo $form->error($model,'main_address'); ?>
        </div>
        
        <!--    
        <div class="row">
            <?php echo $form->labelEx($model,'secondary_address'); ?>
            <?php echo $form->textField($model,'secondary_address',array('size'=>60,'maxlength'=>90)); ?>
            <?php echo $form->error($model,'secondary_address'); ?>
        </div>
        -->
      </td>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'province_id'); ?>
            <?php echo $form->dropDownList($model,'province_id', $provinces ); ?>
            <?php echo $form->error($model,'province_id'); ?>
        </div>
      </td>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'postal_code'); ?>
            <?php echo $form->textField($model,'postal_code',array('size'=>20,'maxlength'=>90)); ?>
            <?php echo $form->error($model,'postal_code'); ?>
        </div>
      </td>
    </tr>
    </table>
    
    <table border="0">
    <tr>
      <td>
        <div class="row">
			<?php echo $form->labelEx($model,'email'); ?>
            <?php echo $form->textField($model,'email',array('size'=>45,'maxlength'=>45)); ?>
            <?php echo $form->error($model,'email'); ?>
	    </div>
      </td>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'mobile_no'); ?>
            <?php echo $form->textField($model,'mobile_no',array('size'=>45,'maxlength'=>45)); ?>
            <?php echo $form->error($model,'mobile_no'); ?>
        </div>
      </td>
    </tr>
    </table>
    </fieldset>
    
    <fieldset>
    <table border="0">
    <tr>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'auto_renew'); ?>
            <?php echo $form->checkBox($model,'auto_renew'); ?>
            <?php echo $form->error($model,'auto_renew'); ?>
        </div>
      </td>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'auto_order'); ?>
            <?php echo $form->checkBox($model,'auto_order'); ?>
            <?php echo $form->error($model,'auto_order'); ?>
        </div>
      </td>
    </tr>
    </table>
    </fieldset>
    
    <!--
	<div class="row">
		<?php echo $form->labelEx($model,'level'); ?>
		<?php echo $form->dropDownList($model,'level',array( 'Bronze'=> 'Bronze', 'Silver'=>'Silver', 'Gold'=>'Gold', 'Titanium'=>'Titanium')); ?>
		<?php echo $form->error($model,'level'); ?>
	</div>
    -->
   
    <fieldset>
    <table border="0">
    <tr>
      <td align="top">
        <div class="row" align="right">
            <?php echo $form->labelEx($model,'status_id'); ?>
            <?php echo $form->dropDownList($model,'status_id', $status ); ?>
            <?php echo $form->error($model,'status_id'); ?>
        </div>
      </td>
      <td align="top">
        <div class="row">
            <!--
            <?php echo $form->labelEx($model,'status_date'); ?>
            <?php echo $form->textField($model,'status_date'); ?>
            <?php echo $form->error($model,'status_date'); ?>
            -->
            <?php echo CHtml::activeLabelEx($model,'status_date'); ?>
            <?php if ( $model->isNewRecord ) { 
			      $date = date("Y-m-d"); ?>
              <?php echo CHtml::activeTextField($model,'status_date',array("id"=>"status_date", 'value'=>$date)); ?>
            <?php } else { ?>
              <?php echo CHtml::activeTextField($model,'status_date',array("id"=>"status_date")); ?>
            <?php } ?>
            <!--&nbsp;(calendar appears when textbox is clicked)-->
            <?php $this->widget('application.extensions.calendar.SCalendar',
                array(
                'inputField'=>'status_date',
                'ifFormat'=>'%Y-%m-%d',
            ));
            ?>
        </div>                    
      </td>
      <td valign="top">
        <div class="row" align="left">
            <?php echo $form->labelEx($model,'status_remark'); ?>
            <?php echo $form->textArea($model,'status_remark', array( 'cols' => 40, 'rows'=>4) ); ?>
            <?php echo $form->error($model,'status_remark'); ?>
        </div>
      </td>
     </tr>  
    </table>
    
    <?php if ( !$model->isNewRecord ) { ?>
    <div class="row">
    
		<?php echo $form->labelEx($model,'date_created'); ?>
		<?php echo $form->textField($model,'date_created', array('disabled'=>'disabled')); ?>
		<?php echo $form->error($model,'date_created'); ?>
        
	</div>
    
    <?php } ?>
    </fieldset>
    
    <fieldset>
    <table border="0">
    <tbody><tr>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'credit_card_name'); ?>
		    <?php echo $form->textField($model,'credit_card_name'); ?>
		    <?php echo $form->error($model,'credit_card_name'); ?>               
        </div>
      </td>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'credit_card_account_no'); ?>
		    <?php echo $form->textField($model,'credit_card_account_no'); ?>
		    <?php echo $form->error($model,'credit_card_account_no'); ?>                     
        </div>
      </td>
      <td>  
        <div class="row">
            <?php echo $form->labelEx($model,'credit_card_type'); ?>
		    <?php echo $form->dropDownList($model,'credit_card_type', 
                                                          array(
														    "Visa" => "Visa",
														    "Mastercard" => "Mastercard",
														    "American Express" => "American Express"
														    
														  ) ); ?>
		    <?php echo $form->error($model,'credit_card_type'); ?>                   
         </div>
      </td>
    </tr>
    </tbody>
    </table>
    <table border="0">
    <tbody><tr>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'bank_name'); ?>
		    <?php echo $form->textField($model,'bank_name'); ?>
		    <?php echo $form->error($model,'bank_name'); ?>               
        </div>
      </td>
      <td>
        <div class="row">
            <?php echo $form->labelEx($model,'bank_account_no'); ?>
		    <?php echo $form->textField($model,'bank_account_no'); ?>
		    <?php echo $form->error($model,'bank_account_no'); ?>                     
        </div>
      </td>
      <td>  
        <div class="row">
            <?php echo $form->labelEx($model,'bank_account_type'); ?>
            <?php echo $form->dropDownList($model,'bank_account_type', 
                                                          array(
														    "Savings" => "Savings",
														    "Checking" => "Checking"
														  ) ); ?>

		    <?php echo $form->error($model,'bank_account_type'); ?>                   
         </div>
      </td>
    </tr>
    </tbody>
    </table>
    </fieldset>

	<div class="row buttons" align="center">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->